package com.accp.hotevent.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import com.accp.hotevent.entity.Event;
import com.accp.hotevent.entity.Notice;
import com.accp.hotevent.entity.User;
import com.accp.hotevent.req.LoginUserRequest;
import com.accp.hotevent.req.RegisterUserRequest;
import com.accp.hotevent.resp.CommonResp;
import com.accp.hotevent.resp.LoginUserResp;
import com.accp.hotevent.service.NoticeService;
import com.accp.hotevent.service.UserService;
import com.accp.hotevent.util.LoggedUserContext;
import com.accp.hotevent.websocket.NoticeServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Base64;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/admin/user")
@Slf4j
public class AdminUserController {

    @Autowired
    private UserService userService;

    @Autowired
    NoticeService noticeService;

    @Autowired
    NoticeServer noticeServer;

    @GetMapping("/list")
    public CommonResp<List<User>> getlist(User user){
        List<User> users = userService.getList(user);
        return CommonResp.success(users);
    }

    @PutMapping("/updateIsBanned")
    public CommonResp updateIsBanned(@RequestBody User user){
        User userdb = userService.getById(user.getId());
        userdb.setBanned(user.isBanned());
        userService.update(user);

        //通知

        Notice notice = Notice.builder()
                .userId(user.getId())
                .build();
        if(user.isBanned()){
            notice.setContent("你被禁言了");
        }else{
            notice.setContent("取消禁言了");
        }

        noticeService.add(notice);
        noticeServer.sendInfo(notice);

        return CommonResp.success();
    }
}
